using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
using ReflectionStudio.Core.Events;
using System.Collections.Generic;
using System;
namespace WPFExcelReport
{
    public partial class VABARTE
    {
        public readonly static VABARTE Instance = new VABARTE();
        VAPARTE _AE05;
        public VAPARTE AE05
        {
            get
            {
                if (_AE05 == null) _AE05 = new VAPARTE();
                return _AE05;
            }
        }
        DataRow dwPF;
        public void CHKABE(Dictionary<string, object> pm)
        {
            dwData = TBMain.NewRow();
            dwData["ABEMANDANT"] = app.Mandant;
            dwData["ABEAUFKRS"] = ((string)pm["ORDERNUM"]).Substring(0, 2);
            dwData["ABEAUFLFD"] = ((string)pm["ORDERNUM"]).Substring(2, 6);
            dwData["ABEAUFPOS"] = ((string)pm["ORDERNUM"]).Substring(8, 3);
            dwData["ABEAFOLGE"] = ((string)pm["ORDERNUM"]).Substring(11, 3);
            DABARTE02(dwData);
            dwData = AE05.TBMain.NewRow();
            dwData["APAEMANDANT"] = app.Mandant;
            dwData["APAEANRKRS"] =(string)pm["ANRKRS"];
            dwData["APAEALFDNR"] =(string)pm["ALFDNR"];
            dwData["APAEAFOLGE"] = (string)pm["AFOLGE"];
            dwData["APAEAEVOR"] = (string)pm["AEVOR"]; 
            SResult = AE05.QKSZ02(dwData);
            foreach (DataRow rset in SResult.Tables[0].Rows)
            {
                DataRow dwABK = TBMain.NewRow();
                SetUpNewRow(ref dwABK, null);
                dwABK["ABEMANDANT"] = app.Mandant;
                dwABK["ABEAUFKRS"] = ((string)pm["ORDERNUM"]).Substring(0, 2);
                dwABK["ABEAUFLFD"] = ((string)pm["ORDERNUM"]).Substring(2, 6);
                dwABK["ABEAUFPOS"] = ((string)pm["ORDERNUM"]).Substring(8, 3);
                dwABK["ABEAFOLGE"] = ((string)pm["ORDERNUM"]).Substring(11, 3);
                dwABK["ABEAEVOR"] = rset["APAEAEVOR"];
                dwABK["ABEMODNR"] = rset["APAEMODNR"];
                dwABK["ABEEINSTNR"] = rset["APAEEINSTNR"];
                dwABK["ABEWERTX"] = rset["APAEWERTX"];
                dwABK["ABEWERTN"] = rset["APAEWERTN"];

                dwABK["ABEPROGNR"] = rset["APAEMODNR"];
                dwABK["ABEEINAUS"] = rset["APAEEINAUS"];
                dwABK["ABEREZEPTKZ"] = rset["APAEREZEPTKZ"];
                dwABK["ABEREZEPTNR"] = rset["APAEREZEPTNR"];
                dwABK["ABEREZEPTST"] = rset["APAEREZEPTST"];
                dwABK["ABEWERKZ"] = rset["APAESTAKZ"];
                dwABK["ABEFAKTOR"] = "00";
                dwABK["ABESTAKZ"] = rset["APAEREZEPTST"];
                dwABK["ABEMODEIN"] = rset["APAEMODEIN"];
                dwABK["ABEIWERTX"] = rset["APAEWERTX"];
                dwABK["ABEIWERTN"] = rset["APAEWERTN"]; 
                dwABK["ABEPFLKZ"] = " ";
                dwABK["ABEMESCHL"] = rset["AMEMESCHL"]; 
                InsertABARTE(dwABK, app.company);
            }
        }
        public DataSet LOADABE(Dictionary<string, object> pm)
        {

            dwData = TBMain.NewRow();
            dwData["ABEMANDANT"] = app.Mandant;
            dwData["ABEAUFKRS"] = (string)pm["KRS"];
            dwData["ABEAUFLFD"] = (string)pm["LFD"];
            dwData["ABEAUFPOS"] = (string)pm["POS"];
            dwData["ABEAFOLGE"] = (string)pm["STEP"];
            dwData["ABEFILLER"] = (string)pm["MKRS"] + (string)pm["MLFD"] + (string)pm["MPOS"];
            SResult = QABE05(dwData);
            return SResult;
        }
        public void SETZLPLC(Dictionary<string, object> pm)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE PLC ";
            or1.Parameters.Add("INTERVAL", OracleType.NVarChar).Value = (string)pm["INTERVAL"];
            or1.Parameters.Add("MSETID", OracleType.NVarChar).Value = (string)pm["MSETID"];
            or1.Parameters.Add("CHANNEL", OracleType.NVarChar).Value = (string)pm["CHANNEL"];
            or1.Parameters.Add("VALUE", OracleType.NVarChar).Value = (string)pm["VALUE"];
            Connect2Proxy(or1, "ZLANSET");
        }
        public void READAM(Dictionary<string, object> pm)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "READ PLC ";
            or1.Parameters.Add("INTERVAL", OracleType.NVarChar).Value = (string)pm["INTERVAL"];
            or1.Parameters.Add("MSETID", OracleType.NVarChar).Value = (string)pm["MSETID"];
            or1.Parameters.Add("CHANNEL", OracleType.NVarChar).Value = (string)pm["CHANNEL"];
            or1.Parameters.Add("VALUE", OracleType.NVarChar).Value = (string)pm["VALUE"];
            Connect2Proxy(or1, "ZLANGET");

        }
        public void STOPAM(Dictionary<string, object> pm)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "STOPREAD PLC ";
            or1.Parameters.Add("INTERVAL", OracleType.NVarChar).Value = (string)pm["INTERVAL"];
            or1.Parameters.Add("MSETID", OracleType.NVarChar).Value = (string)pm["MSETID"];
            or1.Parameters.Add("CHANNEL", OracleType.NVarChar).Value = (string)pm["CHANNEL"];
            or1.Parameters.Add("VALUE", OracleType.NVarChar).Value = (string)pm["VALUE"];
            Connect2Proxy(or1, "ZLANSTOPAM");
        }

        public void GETABEAV(Dictionary<string, object> pm)
        {
            //dwReturn["ABEAEVOR"]="
            string BDEKEY = "0001.010.010";

            Dictionary<string, object> BDEV = (Dictionary<string, object>)pm["BDEV"];
            dwData = TBMain.NewRow();
            dwData["ABEMANDANT"] = app.Mandant;
            dwData["ABEAUFKRS"] = (string)pm["KRS"];
            dwData["ABEAUFLFD"] = (string)pm["LFD"];
            dwData["ABEAUFPOS"] = (string)pm["POS"];
            dwData["ABEAFOLGE"] = (string)pm["STEP"];
            dwData["ABEFILLER"] = (string)pm["MKRS"] + (string)pm["MLFD"] + (string)pm["MPOS"];
            SResult = QABE05(dwData);
            foreach (KeyValuePair<string, object> kp in BDEV)
            {
                BDEKEY = kp.Key;
                filter = "BDEKEY='" + BDEKEY.Replace(".", "") + "'";
                rows = SResult.Tables[0].Select(filter);
                foreach (DataRow dwABK in rows)
                {
                    dwABK["ABEIWERTX"] = ((string)kp.Value).Trim().PadRight(16);
                    try
                    {
                        double value = System.Convert.ToDouble(kp.Value);
                        dwABK["ABEIWERTN"] = Helper.Left("0000000000000000" + (value * 1000000).ToString(), 16);
                    }
                    catch (Exception ex)
                    {


                    }
                    UABE01(dwABK);
                }
            }

        }


    }
    public partial class VABARTE
    {
        public string ABEIWERTX { get { if (dwMaster == null) return ""; return dwMaster["ABEIWERTX"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEIWERTX"] = value; OnPropertyChanged("ABEIWERTX", value); } } //lENGth 16
        public string ABEIWERTN { get { if (dwMaster == null) return ""; return dwMaster["ABEIWERTN"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEIWERTN"] = value; OnPropertyChanged("ABEIWERTN", value); } } //lENGth 16
        public string ABEWERTX { get { if (dwMaster == null) return ""; return dwMaster["ABEWERTX"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEWERTX"] = value; OnPropertyChanged("ABEWERTX", value); } } //lENGth 16
        public string ABEWERTN { get { if (dwMaster == null) return ""; return dwMaster["ABEWERTN"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEWERTN"] = value; OnPropertyChanged("ABEWERTN", value); } } //lENGth 16

        #region======ColumnSchema==========
        /*
                 public string ABEMANDANT { get { if (dwMaster == null) return ""; return dwMaster["ABEMANDANT"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEMANDANT"] = value; OnPropertyChanged("ABEMANDANT", value); } } //lENGth 2
                 public string ABEAUFKRS { get { if (dwMaster == null) return ""; return dwMaster["ABEAUFKRS"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEAUFKRS"] = value; OnPropertyChanged("ABEAUFKRS", value); } } //lENGth 2
                 public string ABEAUFLFD { get { if (dwMaster == null) return ""; return dwMaster["ABEAUFLFD"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEAUFLFD"] = value; OnPropertyChanged("ABEAUFLFD", value); } } //lENGth 6
                 public string ABEAUFPOS { get { if (dwMaster == null) return ""; return dwMaster["ABEAUFPOS"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEAUFPOS"] = value; OnPropertyChanged("ABEAUFPOS", value); } } //lENGth 3
                 public string ABEAFOLGE { get { if (dwMaster == null) return ""; return dwMaster["ABEAFOLGE"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEAFOLGE"] = value; OnPropertyChanged("ABEAFOLGE", value); } } //lENGth 3
                 public string ABEAEVOR { get { if (dwMaster == null) return ""; return dwMaster["ABEAEVOR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEAEVOR"] = value; OnPropertyChanged("ABEAEVOR", value); } } //lENGth 4
                 public string ABEMODNR { get { if (dwMaster == null) return ""; return dwMaster["ABEMODNR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEMODNR"] = value; OnPropertyChanged("ABEMODNR", value); } } //lENGth 3
                 public string ABEEINSTNR { get { if (dwMaster == null) return ""; return dwMaster["ABEEINSTNR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEEINSTNR"] = value; OnPropertyChanged("ABEEINSTNR", value); } } //lENGth 3
                 public string ABEPROGNR { get { if (dwMaster == null) return ""; return dwMaster["ABEPROGNR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEPROGNR"] = value; OnPropertyChanged("ABEPROGNR", value); } } //lENGth 4
                 public string ABEEINAUS { get { if (dwMaster == null) return ""; return dwMaster["ABEEINAUS"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEEINAUS"] = value; OnPropertyChanged("ABEEINAUS", value); } } //lENGth 1
                 public string ABEREZEPTKZ { get { if (dwMaster == null) return ""; return dwMaster["ABEREZEPTKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEREZEPTKZ"] = value; OnPropertyChanged("ABEREZEPTKZ", value); } } //lENGth 1
                 public string ABEREZEPTNR { get { if (dwMaster == null) return ""; return dwMaster["ABEREZEPTNR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEREZEPTNR"] = value; OnPropertyChanged("ABEREZEPTNR", value); } } //lENGth 10
                 public string ABEREZEPTST { get { if (dwMaster == null) return ""; return dwMaster["ABEREZEPTST"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEREZEPTST"] = value; OnPropertyChanged("ABEREZEPTST", value); } } //lENGth 1
                 public string ABEWERKZ { get { if (dwMaster == null) return ""; return dwMaster["ABEWERKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEWERKZ"] = value; OnPropertyChanged("ABEWERKZ", value); } } //lENGth 14
                 public string ABEFAKTOR { get { if (dwMaster == null) return ""; return dwMaster["ABEFAKTOR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEFAKTOR"] = value; OnPropertyChanged("ABEFAKTOR", value); } } //lENGth 2
                 public string ABESTAKZ { get { if (dwMaster == null) return ""; return dwMaster["ABESTAKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABESTAKZ"] = value; OnPropertyChanged("ABESTAKZ", value); } } //lENGth 1
                 public string ABEMODEIN { get { if (dwMaster == null) return ""; return dwMaster["ABEMODEIN"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEMODEIN"] = value; OnPropertyChanged("ABEMODEIN", value); } } //lENGth 1
                 public string ABENEUBEN { get { if (dwMaster == null) return ""; return dwMaster["ABENEUBEN"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABENEUBEN"] = value; OnPropertyChanged("ABENEUBEN", value); } } //lENGth 8
                 public double ABENEUDAT { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["ABENEUDAT"].ToString()); } set { if (dwMaster == null) return; dwMaster["ABENEUDAT"] = value; OnPropertyChanged("ABENEUDAT", value); } } //lENGth 0
                 public string ABEPFLKZ { get { if (dwMaster == null) return ""; return dwMaster["ABEPFLKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEPFLKZ"] = value; OnPropertyChanged("ABEPFLKZ", value); } } //lENGth 1
                 public string ABEDRUCKKZ { get { if (dwMaster == null) return ""; return dwMaster["ABEDRUCKKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEDRUCKKZ"] = value; OnPropertyChanged("ABEDRUCKKZ", value); } } //lENGth 1
                 public string ABERUEKZ { get { if (dwMaster == null) return ""; return dwMaster["ABERUEKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABERUEKZ"] = value; OnPropertyChanged("ABERUEKZ", value); } } //lENGth 1
                 public string ABEREZPOS { get { if (dwMaster == null) return ""; return dwMaster["ABEREZPOS"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEREZPOS"] = value; OnPropertyChanged("ABEREZPOS", value); } } //lENGth 4
                 public string ABEMETHODE { get { if (dwMaster == null) return ""; return dwMaster["ABEMETHODE"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEMETHODE"] = value; OnPropertyChanged("ABEMETHODE", value); } } //lENGth 5
                 public string ABEMWERT { get { if (dwMaster == null) return ""; return dwMaster["ABEMWERT"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEMWERT"] = value; OnPropertyChanged("ABEMWERT", value); } } //lENGth 1
                 public string ABEMESCHL { get { if (dwMaster == null) return ""; return dwMaster["ABEMESCHL"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEMESCHL"] = value; OnPropertyChanged("ABEMESCHL", value); } } //lENGth 2
                 public string ABEFILLER { get { if (dwMaster == null) return ""; return dwMaster["ABEFILLER"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABEFILLER"] = value; OnPropertyChanged("ABEFILLER", value); } } //lENGth 18
        */
        #endregion
    }
}
